<template>
	<view class="container">
		
		<view class="reportView">
			<uni-row class="uni-row">
				<uni-col>
					<text class="title">角色选择：</text>
					<view class="input-item flex align-center">
					  <uni-data-picker class="picker" placeholder="请选择角色" :map="map" popup-title="请选择归属机构" :localdata="roleList" v-model="deptId" >
					  </uni-data-picker>
					</view>
				</uni-col>
			</uni-row>		
		</view>
		<view class="submit-view">
			<button class='submit'  @tap="clickBtn">保存</button>
		</view>
	</view>
</template>
<script>
	import { assignUserRole,getRole} from '@/api/system/user.js'
	export default{
		data(){
			return{
				id:null,
				FormData:{
				},
				map:{
					text:'name',
					value:'id'
				},
				roleList:[],
				deptId:null
			}
		},
		onLoad(e) {
			this.id = e.id
			this.getData()
		},
		methods:{
			getData(){
				getRole().then(res=>{
					this.roleList = res.data
				})
			},
			clickBtn(){
				if(this.deptId != null){
					let data={
						userId:this.id,
						deptId:this.deptId
					}
					assignUserRole(data).then(res=>{
						if(res.data === true){
							uni.navigateBack({
								delta:1
							})
						}
					})
				}else{
					this.$modal.msgError("请选择角色")
				}
				
			}
		}
	}
</script>

<style lang="scss">
	.container{
		background-color: #fff;
		height:100vh;
		.reportView{
			width: calc(100% - 80rpx);
			margin: 0 auto;
			.title{
				font-size: 14px;
				font-family: Inter-Bold, Inter;
				font-weight: bold;
				color: #000000;
				line-height: 40px;
				margin-left: 10px;
			}
			.input-item{
				background-color: #ffffff;
				height: 50px;
				border-radius: 10px;
				opacity: 1;
				border: 1px solid #508CFF;
				padding-left: 10px;
				
				/deep/ .uni-select{
					border: none;
					border-bottom: none;
					padding-left: 0;
				}
				.place{
					font-size: 12px;
				}
				.picker{
					overflow: hidden;
					/deep/ .input-value-border{
						border: none;
						box-shadow: none;
					}
					/deep/ .selected-list{
						width: 230px;
						overflow: hidden;
					}
				}
			}
			.uni-row{
				margin-bottom: 20px;
			}
			
		}
		.submit{
			margin-top: 40px;
			color: #fff;
			width: 100px;
			height: 30px;
			font-size: 14px;
			line-height: 30px;
			background: #508CFF;
			border-radius: 5px 5px 5px 5px;
		}
	}
</style>